<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>填写订单</title>
    <link rel="stylesheet" href="../../../css/aui.css" />
    <link rel="stylesheet" href="../../../css/api.css" />
    <link rel="stylesheet" href="../../../css/my/apply.css" />

    <link rel="stylesheet" href="../../../css/index/aircraft/plane_order.css">
    <link rel="stylesheet" href="../../../css/iconfont/iconfont.css" />
    <style>
        input[type="radio"] {
            content: "\a0";
            /*不换行空格*/
            display: inline-block;
            vertical-align: middle;
            font-size: 18px;
            width: 1em;
            height: 1em;
            margin-right: .4em;
            border-radius: 50%;
            /*border: 1px solid #01cd78;*/
            text-indent: .15em;
            line-height: 1;
        }
    </style>
</head>

<body style="cursor: pointer">

    <div class="aui-content" style="background:#F6F6F6;">
        <div class="detail">
            <div class="detail_time">
                <div class="start_time">
                    <p class="s_time">213</p>
                    <p class="s_place">北京</p>
                </div>
                <div class="expenditure_time">
                    <span class="duration">2小时</span>
                    <i class="iconfont"></i>
                </div>
                <div class="end_time">
                    <p class="e_time">17:40</p>
                    <p class="e_place">上海</p>
                </div>
            </div>
        </div>
        <div class="fly_info">
            <div>
                <span class="date_left">单程</span>
                <span class="date_right"></span>
            </div>
            <div style="clear: both;"></div>
            <div class="fly_number">
                <div class="fly_left">
                    <p class="plane_name" style="font-size: 0.7rem;color: black;"></p>
                    <p class="plane_number" style="font-size: 0.7rem;color: black;"></p>
                </div>
                <div class="fly_center">
                    <p class="seat_type" style="color:black;"></p>
                    <p><span class="discount"></span><span class="plane_price" style="color: red;font-weight: bold;"></span></p>
                </div>
                <div class="fly_right">
                    <p style="color:black;">燃油</p>
                    <p class="fuel_charge" style="color: red;font-weight: bold;"></p>
                </div>
                <div class="fly_right" style="width: 20%;">
                    <p style="color:black;">机建</p>
                    <p class="cover_charge" style="color: red;font-weight: bold;"></p>
                </div>
            </div>
        </div>
        <div class="policy_content aui-hide">
            <div class="u_title">政策违规<span style="font-weight: normal;font-size: 0.6rem;">（单程）</span></div>
            <div class="policy_info">
                <span class="policy_cause"></span>,请选择原因：
            </div>
            <div class="aui-list-item-input" style="height: 1.5rem;line-height: 1.5rem;padding: 0 0.6rem; margin-bottom: 0.5rem">
                <select class="violation hotel_type violation_reason" name="violation_reason" style="width: 50%;height: 100%;margin-right: 0.5rem;font-size: 0.6rem;font-weight: bold;line-height: 1.5rem;">
                <option value="">请选择</option>

            </select>
            </div>
        </div>
        <div style="margin-top: 0.5rem;background: #fff;overflow: auto;">
            <div class="u_title">登机人</div>
        </div>
        <div class="passenger">

        </div>

        <div style="margin-top: 0.5rem;background: #fff;overflow: auto;" class="aui-hide">
            <div class="u_title">选择要提交的成本中心</div>
            <div id="select_cost">

            </div>
            <!-- <div class="u_info" id="select_cost">
                <div class="aui-list-item-inner" style="overflow: auto;text-align: center">
                    <div class="aui-list-item-label" style="width:20%;float: left;height: 2rem;line-height: 2rem;">
                        <input class='aui-radio' type="radio" name="cost_id">
                    </div>
                    <div class="aui-list-item-input" style="width:50%;float: left;height: 2rem;line-height: 2rem;">
                        <div style="float: left;">
                            <span style="font-size: 0.8rem;font-weight: bold;">孟生伟成本中心</span>
                        </div>
                    </div>
                    <div style="height: 2rem;line-height: 2rem;float:right;color: #FF0000;font-size: 0.7rem">不需要审批</div>
                </div>
            </div> -->
        </div>

        <div class="aui-content box-shodow padding-10 mt-30" style="clear: both;margin-top: 0.5rem;background: #fff;">
            <div class="u_title">联系人</div>
            <div class="aui-card-list-content ml-10" style="">
                <ul class="aui-list aui-media-list contact" id="contact">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;" onclick="select_contant()">
                        <div class="aui-media-list-item-inner">
                            <div style="height: 100%;width:20%;vertical-align: middle;padding: 0rem 0.5rem;float: left;">
                                <div style="border-radius: 50%;background: #F9C003;text-align: center;width: 2rem;height: 2rem;line-height: 2rem;">
                                    <span style="font-weight: bold;font-size: 1rem;color: #fff;" class="contact_char"></span>
                                </div>
                            </div>
                            <div class="aui-list-item-inner aui-list-item-arrow" style="line-height: 2rem;">
                                <span class="contact_name" style="color: #000;"></span>
                                <span class="float-right conatct_mobile" style="font-size: 15px;color: #000;padding-left: 2rem"></span>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <div class="aui-content box-shodow padding-10 mt-30" style="clear: both;margin-top: 0.5rem;background: #fff;">
            <div class="u_title">为您的出行添加保障</div>
            <div class="aui-card-list-content ml-10 insurance" id="private_insurance">
                <div class="aui-list-item-inner" id='plane_insurance'>
                    <!-- <div class="aui-list-item-input" style="padding:0.5rem;overflow:auto;border-bottom: 1px solid #D8D8D8;">
                        <label style="color:#A9A9A9;float:left;height:2.5rem;line-height:2.5rem;"><input class="aui-radio order_radio" checked type="radio" name="insurance_type"  value="1"></label>
                        <div style="float:left;">
                            <p><span style="font-size:0.8rem;color:black;margin-right:0.5rem;">航意险</span><span>最高保额320万保额</span></p>
                            <p>买一份保险，多一份安心</p>
                        </div>
                        <div style="float:right;height:2.5rem;line-height:2.5rem;">
                            <span style="color:red;font-weight:bold;">￥30</span><span>/份×1</span>
                        </div>
                    </div>
                    <div class="aui-list-item-input" style="padding:0.5rem; overflow:auto;border-bottom: 1px solid #D8D8D8;">
                        <label style="color:#A9A9A9;float:left;height:2.5rem;line-height:2.5rem;"><input class="aui-radio order_radio" type="radio" name="insurance_type"  value="2"></label>
                        <div style="float:left;">
                            <p><span style="font-size:0.8rem;color:black;margin-right:0.5rem;">延误险</span><span>最高保额320万保额</span></p>
                            <p>买一份保险，多一份安心</p>
                        </div>
                        <div style="float:right;height:2.5rem;line-height:2.5rem;">
                            <span style="color:red;font-weight:bold;">￥30</span><span>/份×1</span>
                        </div>
                    </div> -->
                </div>
            </div>
        </div>

        <!--<div class="apply">-->
        <!--<div class="u_title" style="border-bottom: 0rem;float: left;">-->
        <!--报销凭证-->
        <!--</div>-->
        <!--<div style="float: right;border-bottom: 0rem;padding: 0.65rem 0.5rem;">-->
        <!--<input type="checkbox" class="aui-switch" checked>-->
        <!--</div>-->
        <!--</div>-->
        <div class="fly_mess">
            <div class="aui-list-item-inner" style="overflow: auto;border-bottom: 1px solid #E0E0E0;padding: 0.5rem;">
                <div class="aui-list-item-label" style="height: 2rem;line-height: 2rem;float: left;font-size: 1rem;font-weight: bold;">
                    附加信息
                </div>
                <div class="aui-list-item-input" style="width:7rem;height: 2rem;line-height: 2rem;float: right;">
                    <input type="text" placeholder="请填写附加信息">
                </div>
            </div>
            <div class="orderAllmoney" style="border-bottom: 1px solid #D8D8D8;">
                <span>订单总额</span><span style="color: red;font-weight:bold;">￥</span><span class="price_all" style="color: red;font-weight:bold;"></span>
                <p>注：总额 = (票价+机建费+燃油费+保险)×出行人数</p>
                <p>未开启保险预订，保险将不算入总额</p>
            </div>
        </div>
        <div class="trave_goal" style="margin-top: 0.5rem;background: #fff;overflow: auto;">
            <div class="u_info">
                <div class="aui-list-item-inner">
                    <div style="border-bottom: 1px solid #DCDCDC;overflow: auto;">
                        <div class="aui-list-item-label card_side u_ticket" style="width:30%;line-height: 2rem;">
                            出行目的
                        </div>
                        <div class="aui-list-item-input" style="float: right;height: 2rem;line-height: 2rem;">
                            <select class="purpose hotel_type trip_cauce" name="trip_cause" style="width: 6rem;height: 100%;margin-right: 1rem;font-size: 0.8rem;font-weight: bold;">
                            <option selected="selected" >商务谈判</option>
                            <option>商务考察/视察</option>
                            <option>学习/培训</option>
                            <option>技术支持</option>
                            <option>会展/展务</option>
                            <option>奖励/旅游</option>
                            <option>其他</option>
                        </select>
                        </div>
                    </div>

                    <div class="aui-list-item-inner" style="border-bottom: 1px solid #D8D8D8;">
                        <div class="aui-list-item-input">
                            <input type="text" name="memo1" placeholder="备注(出行目的为其他是必填)">
                        </div>
                    </div>
                    <!-- <div class="aui-list-item-inner" style="border-bottom: 1px solid #D8D8D8;">
                    <div class="aui-list-item-input" >
                        <input type="text" name="oa_number" placeholder="OA出差申请单">
                    </div>
                </div> -->
                </div>
            </div>
        </div>

        <div style="padding: 1rem;">
            <div class="aui-btn aui-btn-primary aui-btn-block order_submit" onclick="submit_order();">提交订单</div>
        </div>

    </div>

</body>

</html>
<script type="text/javascript" src="../../../script/aui/api.js"></script>
<script type="text/javascript" src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script src="../../../script/extend/date.js"></script>
<script type="text/javascript" src="../../../script/config.js"></script>
<script src="../../../script/extend/doT.min.js"></script>
<script src="../../../script/aui/aui-dialog.js"></script>
<script src="../../../script/extend/jquery.charfirst.pinyin.js"></script>
<script type="text/javascript" src="../../../script/aui/aui-toast.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>
<script src="../../../script/sort.js"></script>
<script src="../../../script/widget/js-time.js"></script>
<script type="text/template" charset="utf-8" id="user_info_tpl">
    {{ for(var i=0;i
    <it.length;i++){ }} {{ if(it.self_type==1 ){ }} <div style="background: #fff;overflow: auto;border-bottom: 1px solid #E0E0E0;width: 100%" class="user_list private_user" display="none">
        <div class="u_info">
            <div style="height: auto;overflow:auto;width:20%;vertical-align: middle;padding: 1.5rem 0.5rem;float: left;">
                <div style="border-radius: 50%;background: #2396F3;text-align: center;width: 2rem;height: 2rem;line-height: 2rem;">
                    <span class="letter" style="font-weight: bold;font-size: 1rem;color: #fff;">{{=it[i].user_name.substring(0, 1)}}</span>
                </div>
            </div>
            {{ if (!it[i].travels_id) { }}
            <div style="float: left;padding: 0.5rem 0rem;width: 80%;" class="sel_card" id='{{=it[i].user_id}}' onclick="select_card_info(this)">
                {{ }else{ }}
                <div style="float: left;padding: 0.5rem 0rem;width: 80%;" class="sel_card" id='{{=it[i].travels_id}}' onclick="select_card_info(this)">

                    {{ } }}

                    <div style="float: left;">
                        <div><span class="user_name">{{=it[i].user_name}}</span></div>
                        <div><span class="card_side send_sms">发送短信</span></div>
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label card_side u_ticket card_type">
                                请选择证件
                            </div>
                            <div class="aui-list-item-input" style="float: right;">
                                <span class="card_side u_ticket card_num"></span>
                            </div>
                        </div>
                    </div>
                    <div style="float: right;margin-top: 1rem;">
                        <i class="iconfont icon-gengduo" style="color:#AAAAAA;font-size: 1.2rem;vertical-align: middle;"></i>
                    </div>
                </div>
            </div>
            <div class="mobile" style="display:none">{{=it[i].mobile}}</div>
            <div class="travel_user_id" style="display:none">{{=it[i].user_id}}</div>
            <div class="travels_id" style="display:none">{{=it[i].travels_id}}</div>
        </div>
        {{ }else{ }}
        <div display="none" style="background: #fff;overflow: auto;border-bottom: 1px solid #E0E0E0;width: 100%" class="user_list public_user">
            <div class="u_info">
                <div style="height: auto;overflow:auto;width:20%;vertical-align: middle;padding: 1.5rem 0.5rem;float: left;">
                    <div style="border-radius: 50%;background: #2396F3;text-align: center;width: 2rem;height: 2rem;line-height: 2rem;">
                        <span class="letter" style="font-weight: bold;font-size: 1rem;color: #fff;">{{=it[i].user_name.substring(0, 1)}}</span>
                    </div>
                </div>
                <div style="float: left;border-bottom: 1px solid #E0E0E0;width: 80%;" class="sel_card" id='{{=it[i].user_id}}' onclick="select_card_info(this)">
                    <div style="float: left;">
                        <div><span class="user_name">{{=it[i].user_name}}</span></div>
                        <div><span class="card_side"><span>{{=it[i].approval_name}}</span><span class="send_sms">发送短信</span></span>
                        </div>
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label card_side u_ticket card_type">
                                请选择证件
                            </div>
                            <div class="aui-list-item-input" style="float: right;">
                                <span class="card_side u_ticket card_num"></span>
                            </div>
                        </div>
                    </div>
                    <div style="float: right;">
                        <i class="iconfont icon-gengduo" style="color:#AAAAAA;font-size: 1.2rem;vertical-align: middle;"></i>
                    </div>
                </div>
                <div class="aui-list-item-inner" id="{{=it[i].user_id}}{{=it[i].mobile}}" onclick="get_policy_list(this)">
                    <div class="aui-hide uid">{{=it[i].user_id}}</div>
                    <div class="aui-list-item-label card_side u_ticket" style="line-height: 2rem;">
                        成本中心
                    </div>
                    <div class="aui-list-item-input" style="float: right;height: 2rem;line-height: 2rem;">
                        <div style="float: left;">
                            <span class="card_side u_ticket cost_name">请选择成本中心</span>
                        </div>
                        <div style="float: right;">
                            <i class="iconfont icon-gengduo" style="color:#AAAAAA;font-size: 1.2rem;vertical-align: middle;"></i>
                        </div>
                    </div>
                </div>
            </div>
            <div class="mobile" style="display:none">{{=it[i].mobile}}</div>
            <div class="travel_user_id" style="display:none">{{=it[i].user_id}}</div>
            <div class="travels_id" style="display:none">{{=it[i].travels_id}}</div>
        </div>
        {{ } }} {{ } }}
</script>
<script type="text/template" charset="utf-8" id="insurance_id">
    {{ for(var j=0;j<it.length;j++){ }} <div class="aui-list-item-input" style="padding:0.5rem;overflow:auto;border-bottom: 1px solid #D8D8D8;">
        <label style="color:#A9A9A9;float:left;height:2.5rem;line-height:2.5rem;">
          <input class="aui-radio order_radio" type="radio" name="insurance_type" onclick="changeIn(this)"  value="">
        </label>
        <div style="float:left;">
            <p>
                <span style="font-size:0.8rem;color:black;margin-right:0.5rem;">{{=it[j].ins_name}}</span>
                <span class="aui-iconfont aui-icon-info" onclick="remarkClick(this)" style="color:#3BA9CF;margin-left:-0.4rem;"></span>
            </p>
            <p>让出行更安心，最高享{{=it[j].amount}}万保障</p>
        </div>
        <div style="float:right;height:2.5rem;line-height:2.5rem;">
            <span style="color:red;font-weight:bold;">￥{{= it[j].discount_prem}}</span><span>/人</span>
            <span class='aui-hide insurance_money'>{{= it[j].discount_prem}}</span>
            <span class='aui-hide instype_code'>{{= it[j].instype_code}}</span>
        </div>
        <div style="padding:0.5rem;overflow:auto;" class="aui-hide insurance_info">
            <div style="font-weight:bold;text-align:center;">{{=it[j].ins_name}}</div>
            <div style="text-align:left;">{{=it[j].description}}</div>
        </div>
        </div>
        {{ } }}
</script>

<script type="text/javascript">
    //初始化航班信息
    var dialog = new auiDialog({});

    var planeInfo, order_self, staff, train, plane_msg, priceMoneyAll, selected_staff, in_money, priceAll, selected_train, isApply, is_insurance, user_id, policy_id, is_violation, userId;
    order_self = parseInt($api.getStorage("order_self"));
    var user_num = '';
    var people_num = '';//出行人数
    var approve_type = '';//审批类型
    apiready = function() {
        "use strict";
        api.parseTapmode();

        planeInfo = api.pageParam.planeInfo; //航班信息
        plane_msg = api.pageParam.plane_msg; //舱位信息
        selected_staff = api.pageParam.selected_staff; //出行人信息
        selected_train = api.pageParam.selected_train; //出行人信息
        isApply = $api.getStorage('isApply'); //是否开启申请单的状态 1开启   0关闭
        userId = $api.getStorage('user_id');
        is_violation = $api.getStorage('is_violation');
        policy_id = $api.getStorage('policy_id');
        $api.getStorage('card_submit_type'); //完成返回页面标识 0火车票 1机票
        //获取常用联系人列表
        ajax({
            url: Config.common.getContact,
            data: {}
        }, function(data) {
            if (data.code === 1) {
                var res = data.data;
                var contact = res[0];
                $('.contact_char').text(makePy(contact.contact_name.substring(0, 1)));
                $('.contact_name').text(contact.contact_name).attr('contact_id', contact.id);
                $('.conatct_mobile').text(contact.contact_mobile);

            } else {
                $('.contact_name').text('暂无常用联系人,请先添加');
                $('.conatct_mobile').text('');
            }
        });
        //监听常用联系人返回值
        api.addEventListener({
            name: 'contactUser'
        }, function(ret, err) {
            if (ret.value.contact_id != null && ret.value.contact_id !== undefined) {
                $('.contact_name').text(ret.value.contact_name).attr('contact_id', ret.value.contact_id);
                $('.conatct_mobile').text(ret.value.contact_mobile);
                var char = makePy(ret.value.contact_name.substring(0, 1));
                $('.contact_char').text(char[0]);
            }
        });

        //获取保险列表
        var params = {};
        params.url = Config.plane.getPlaneAddInsurance;
        if (order_self === 1) {
            params.data = {
                order_self: 1
            };
        } else {
            params.data = {
                order_self: 2,
                company_id: $api.getStorage('company_id'),
                policy_id: policy_id
            };
        }
        ajax(params, function(data) {
            if (data.code === 1) {
                if (data.data === '') {
                    in_money = 0;
                    is_insurance = 0;
                    // var html_str = '';
                    // html_str = '<div style="color:red;padding:0.5rem;">未开启保险预订</div>';
                    $('#plane_insurance').parent().parent().addClass('aui-hide');
                } else {
                    is_insurance = 1;
                    var evalText = doT.template($('#insurance_id').text());
                    $('#plane_insurance').parent().parent().removeClass('aui-hide').html(evalText(data.data));

                    $("input[name='insurance_type']").eq(0).attr("checked", "checked");

                    in_money = $("input[name='insurance_type']:checked").parent().parent().find('.insurance_money').text();

                }
                main();
            } else {
                $alert(data.msg);
            }
        });

        // is_insurance = 0;
        // var html_str = '';
        // html_str = '<div style="color:red;padding:0.5rem;">未开启保险预订</div>';
        // $('#plane_insurance').html(html_str);
        var param = {};
        var flight_number = planeInfo.flight_number; //航班号
        var date = planeInfo.date; //起飞日期
        var start = planeInfo.off_code; //出发机场code
        var arrive = planeInfo.ground_code; //目地机场名称code
        var time = planeInfo.time; //起飞时间
        var carrier = planeInfo.carrier; //航空公司两字码
        $('.seat_type').text(plane_msg.space_type); //舱位类型
        $('.discount').text(plane_msg.discount + '折'); //折扣
        $('.plane_price').text('￥' + plane_msg.now_price); //舱位价格
        $('.plane_name').text($api.getStorage('carrier_fullname')); //航空公司名
        $('.plane_number').text(flight_number); //航班号
        $('.cover_charge').text('￥' + $api.getStorage('cover_charge')); //机建
        $('.fuel_charge').text('￥' + $api.getStorage('fuel_charge')); //燃油

        //判断是否违规
        if (order_self !== 1) {
            if ($api.getStorage('trip_policy') === 0 || is_violation === 'true') {
                $('.policy_content').removeClass('aui-hide');
                var check_msg = '<span style="color:#ff0000">' + $api.getStorage('check_msg') + '</span>';
                $('.policy_cause').html(check_msg);
                ajax({
                    url: Config.plane.getPlaneViolation,
                    data: {
                        productId: 1,
                        company_id: $api.getStorage('company_id')
                    }
                }, function(data) {
                    if (data.code === 1) {
                        var res = data.data;
                        var html = '';
                        $.each(res, function(key, val) {
                            if (key === 0) {
                                html += '<option selected="selected" value="' + val.id + '">' + val.reason_name + '</option>';
                            } else {
                                html += '<option value="' + val.id + '">' + val.reason_name + '</option>';
                            }
                        });
                        $('.violation').append(html);
                    }
                })
            } else {
                $('.policy_content').addClass('aui-hide');
            }
        }

        var date1 = date.split('/');
        $('.start_date').text(date1[1] + '月' + date1[2] + '日');
        param.url = Config.plane.flightInfo;
        param.data = {
            from: start,
            arrive: arrive,
            date: date,
            time: time,
            carrier: carrier,
            flight_no: flight_number
        };
        getPlaneList(param);

        //判断订单类型
        // var selected_staff = $api.getStorage('selected_staff');
        // var selected_train = $api.getStorage('selected_train');
        // if (order_self == 1) {
        //     $('#sel_cost').addClass('aui-hide');
        //     $('.trave_goal').addClass('aui-hide');
        //
        // } else {
        //     $('#sel_cost').removeClass('aui-hide');
        //     $('.trave_goal').removeClass('aui-hide');
        // }



    };

    function main() {
        var param = {};
        if (order_self === 2) {
            param = {
                staffIds: userId
            };
        } else if (order_self === 1) {
            staff = selected_staff === '' ? '' : selected_staff.join(',');
            train = selected_train === '' ? '' : selected_train.join(',');
            param = {
                staffIds: staff,
                noStaffIds: train
            };
        } else {
            staff = selected_staff;
            train = selected_train;
            param = {
                staffIds: staff,
                noStaffIds: train
            };
        }
        ajax({
            url: Config.common.getTravelUser,
            data: param
        }, function(data) {
            if (data.code === 1) {
              people_num = data.count;//出行人数
              if (people_num == 1) {
                approve_type = data.data[0].approval_name;//审批类型
              }
                data.data.self_type = order_self;
                var res = data.data;
                user_num = res.length;
                //总金额
                if (is_insurance == 1 && in_money == 0) {
                    in_money = $("input[name='insurance_type']:checked").parent().parent().find('.insurance_money').text();
                }
                /*console.log(Date.parse(new Date()));
                if (in_money === '') {
                    setTimeout(function () {},1000);
                }
                console.log(Date.parse(new Date()));
                console.log(in_money);*/
                priceAll = parseInt(plane_msg.now_price) + parseInt($api.getStorage('cover_charge')) + parseInt($api.getStorage('fuel_charge'));

                priceMoneyAll = (priceAll * user_num) + (parseInt(in_money) * user_num);

                $('.price_all').text(priceMoneyAll);


                var tpl = document.getElementById("user_info_tpl").innerHTML;
                document.getElementsByClassName('passenger')[0].innerHTML = doT.template(tpl)(res);
                first_letter();
                if (order_self !== 1) {
                    get_cost_info();
                } else {
                    $('#sel_cost').addClass('aui-hide').parent().addClass('aui-hide');
                }
                get_card_info();
            }
        });
    }

    //监听保险选择事件
    function changeIn(obj) {
        in_money = '';
        in_money = $(obj).parent().parent().find('.insurance_money').text();
        priceMoneyAll = priceAll * user_num + parseInt(in_money) * user_num;
        $('.price_all').text(priceMoneyAll);
    }

    //保险详情弹框
    function remarkClick(obj) {
        var remarkExit = $(obj).parent().parent().parent().find('.insurance_info').html();
        var remarkExits = remarkExit.replace(/\n/g, '<br>');
        dialog.alert({
            msg: remarkExits,
            buttons: ['确定']
        }, function(ret) {
            console.log(ret)
        })
    }

    //获取航班信息接口
    function getPlaneList(param) {
        ajax(param, function(data) {
            if (data.code === 1) {
                $('.expenditure_time i').addClass('icon-lianjie');
                $('.s_time').text(data.data.from_time); //起飞时间
                $('.e_time').text(data.data.arrive_time); //到达时间
                $('.s_place').text($api.getStorage('aircraf_start_site') + data.data.from_address); //起飞站
                $('.e_place').text($api.getStorage('aircraf_end_site') + data.data.to_address); //到达站
                $('.duration').text(data.data.total_time); //时长
                var date2 = data.data.from_date.split('-');
                $('.date_right').text(date2[0] + '年' + date2[1] + '月' + date2[2] + '日');
            } else {
                $toast('获取航班信息失败');
            }
        })
    }

    //机票订单提交
    function submit_order() {
        $('.order_submit').removeAttr('onclick');
        var flag = false;
        var toast = new auiToast();
        if (order_self !== 1) {
            $('.public_user').removeAttr('display');
            //差旅政策数据
            var trip_policy = {
                'cost_center_id': $('input:radio:checked').val(),
                'order_self': order_self,
                'policy_id': policy_id,
                'is_violation': is_violation,
            };

            //出行人数据
            var trip_users = [];
            var train_user_names = [];
            var train_users_ids = [];

            $(".user_list").each(function() {
                var obj = $(this);
                var travel_user_id = obj.find('.travel_user_id').text();
                var travels_id = obj.find('.travels_id').text();
                var travel_user_name = obj.find('.user_name').text();
                var travel_user_type = 1;
                var travel_user_idcard_id = obj.find('.card_type').attr('card_id');
                var travel_user_idcard_type = obj.find('.card_type').text();
                var travel_user_idcard_number = obj.find('.card_num').text();
                var travel_user_mobile = obj.find('.mobile').text();
                var message_confirm = obj.find('.card_type').attr('message_confirm');
                var cost_id = obj.find('.cost_name').attr('cost_id');
                //判断当前是否有成本中心
                if (cost_id == null || cost_id == 'undefined' || cost_id == '') {
                    toast.fail({
                        title: '请选择成本中心',
                        duration: 2000,
                    });
                    $('.order_submit').attr('onclick', 'submit_order()');
                    flag = true;
                }

                if (travels_id == 'undefined') {
                    travel_user_type = 1;
                } else {
                    travel_user_id = travels_id;
                    travel_user_type = 0;
                }

                var users = {
                    'travel_user_id': travel_user_id,
                    'travel_user_name': travel_user_name,
                    'travel_user_type': travel_user_type,
                    'travel_user_idcard_id': travel_user_idcard_id,
                    'travel_user_idcard_type': travel_user_idcard_type,
                    'travel_user_idcard_number': travel_user_idcard_number,
                    'travel_user_mobile': travel_user_mobile,
                    'ticket_type': 1,
                    'message_confirm': message_confirm,
                    'cost_center_id': cost_id
                };

                $.each(users, function(i, n) {
                    if (n == null || n == 'undefined' || n == '') {
                        toast.fail({
                            title: '请选择证件信息',
                            duration: 2000,
                        });
                        $('.order_submit').attr('onclick', 'submit_order()');
                        flag = true;
                    }
                })

                train_user_names.push(travel_user_name);
                train_users_ids.push(travel_user_id);
                trip_users.push(users);
            });
        } else {
            $('.private_user').removeAttr('display');
            //差旅政策数据
            // var is_violation = $api.getStorage('is_violation');
            var trip_policy = {
                'cost_center_id': '',
                'order_self': order_self,
                'policy_id': '',
                'is_violation': is_violation,
            };
            //出行人数据
            var trip_users = [];
            var train_user_names = [];
            var train_users_ids = [];

            $(".user_list").each(function() {
                var obj = $(this);
                var travel_user_id = obj.find('.travel_user_id').text();
                var travels_id = obj.find('.travels_id').text();
                var travel_user_name = obj.find('.user_name').text();
                var travel_user_type = 1;
                var travel_user_idcard_id = obj.find('.card_type').attr('card_id');
                var travel_user_idcard_type = obj.find('.card_type').text();
                var travel_user_idcard_number = obj.find('.card_num').text();
                var travel_user_mobile = obj.find('.mobile').text();
                var message_confirm = obj.find('.card_type').attr('message_confirm');
                if (travels_id == 'undefined') {
                    travel_user_type = 1;
                } else {
                    travel_user_id = travels_id;
                    travel_user_type = 0;
                }

                var users = {
                    'travel_user_id': travel_user_id,
                    'travel_user_name': travel_user_name,
                    'travel_user_type': travel_user_type,
                    'travel_user_idcard_id': travel_user_idcard_id,
                    'travel_user_idcard_type': travel_user_idcard_type,
                    'travel_user_idcard_number': travel_user_idcard_number,
                    'travel_user_mobile': travel_user_mobile,
                    'ticket_type': 1,
                    'message_confirm': message_confirm,
                    'cost_center_id': ''
                };

                $.each(users, function(i, n) {
                    if (i != 'cost_center_id' && i != 'travel_user_type') {
                        if (n == null || n == 'undefined' || n == '') {
                            toast.fail({
                                title: '请选择证件信息',
                                duration: 2000,
                            });
                            $('.order_submit').attr('onclick', 'submit_order()');
                            flag = true;
                        }
                    }
                })

                train_user_names.push(travel_user_name);
                train_users_ids.push(travel_user_id);
                trip_users.push(users);
            });
        }

        //机票数据
        var trip_details = {
            "airline_name": $api.getStorage('carrier_fullname'), //航空公司名称
            "alrline_model": planeInfo.airline_model, //机型
            "discount": plane_msg.discount, //折扣
            "flight_hours": planeInfo.flight_hours, //时长（小时）
            "flight_minute": planeInfo.flight_minute, //时长（分钟）
            "flight_number": planeInfo.flight_number, //航班号
            "price": plane_msg.now_price, //价格
            "cover_charge": $api.getStorage('cover_charge'), //机建
            "shipping_space": plane_msg.space_type, //舱位类型
            "take_off_floor": planeInfo.take_off_floor, //起飞航站楼
            "take_off_place": $api.getStorage('aircraf_start_site') + planeInfo.take_off_place, //起飞机场名
            "take_off_date": planeInfo.date, //起飞日期
            "take_off_time": planeInfo.time, //起飞时间
            "to_ground_floor": planeInfo.to_ground_floor, //到达航站楼
            "to_ground_place": $api.getStorage('aircraf_end_site') + planeInfo.to_ground_place, //到达机场名
            "to_ground_time": planeInfo.end_time, //到达时间
            "fuel_charge": $api.getStorage('fuel_charge'), //燃油费
            "purchase_price": 0, //采购价，第三方给的，todo，目前写为0
            "ins_type_code": $("input[name='insurance_type']:checked").parent().parent().find('.instype_code').text(), //保险类型
            "ins_price": $("input[name='insurance_type']:checked").parent().parent().find('.insurance_money').text(), //保险价格
            "office": plane_msg.office, //是否是官网直销价
        };
        //订单相关数据
        var violation_reason = '';
        if (is_violation == 'true') {
            violation_reason = $('.violation_reason option:selected').text();
        }
        var trip_cause = $('.trip_cauce option:selected').text();
        if (trip_cause == '其他') {
            //获取备注
            var memo1 = $('input[name=memo1]').val();
            if (memo1 == '') {
                toast.fail({
                    title: '请说明出行原因',
                    duration: 2000,
                });
                $('.order_submit').attr('onclick', 'submit_order()');
                flag = true;
            }
        }
        var trip_order = {
            'trip_users': train_user_names.toString(),
            'trip_users_ids': train_users_ids.toString(),
            'consignee_id': $('.contact_name').attr('contact_id'),
            'trip_cause': trip_cause,
            'memo1': $('input[name=memo1]').val(),
            'oa_number': oa_number = $api.getStorage('isApply') == 1 ? $api.getStorage('oa_number') : '',
            'violation_reason': violation_reason,
            'book_user_id': userId,
            'create_module': 'company'
        };
        // sessionStorage.removeItem('send_sms');
        //判断联系人是否为空
        if ($('.contact_name').text() == '' || $('.conatct_mobile').text() == '') {
            toast.fail({
                title: '请选择联系人',
                duration: 2000,
            });
            $('.order_submit').attr('onclick', 'submit_order()');
            flag = true;
        }
        if (flag) {
            return false;
        }
        //发起ajax请求
        var param = {
            trip_details: trip_details,
            trip_users: trip_users,
            trip_order: trip_order,
            trip_policy: trip_policy,
            office: plane_msg.office,
            date: planeInfo.date,
            time: planeInfo.time,
            carrier: planeInfo.carrier,
            consignee_mobile: $('.conatct_mobile').text(),
            flightNo: planeInfo.flight_number.slice(2),
            code: plane_msg.shipping_code,
            boardPoint: planeInfo.off_code,
            offPoint: planeInfo.ground_code
        };
        var params = {};
        params.url = Config.plane.planeSubmitOrder;
        params.data = param;
        ajax(params, function(data) {
            if (data.code === 1) {
                //获取要花费的总额
                var total_price = $('.price_all').text();
                api.openWin({
                    name: 'order_success_win',
                    url: '../common/order_success_win.html',
                    slidBackEnabled:false,
                    pageParam: {
                        price: total_price
                    }
                });

            } else {
                alert('预定失败,请稍后再试!');
                $('.order_submit').attr('onclick', 'submit_order()');
            }
        });
    }
    //获取用户的拼音首字母
    function first_letter() {
        $('.letter').each(function() {
            var name = $(this).text();
            var letter = makePy(name);
            $(this).text(letter[0].toUpperCase());
        });
    }

    //获取常用联系人列表
    function select_contant() {
        // $api.setStorage('getStaffUser', 1); //火车票0   机票1
        api.openWin({
            name: 'contact_list_win',
            url: '../common/contact_list_win.html',
            pageParam: {}
        });

    }

    //获取成本中心列表
    function get_policy_list(obj) {
        cost_id = $(obj).attr('id');
        var u_id = $(obj).find('.uid').text();
        api.openWin({
            name: 'cost_center_frm',
            url: '../common/cost_center_frm.html',
            pageParam: {
                user_id: u_id
            }
        });
    }
    //获取选中的成本中心
    function get_cost_info() {
        var cost_center_id = '';
        //接收监听成本中心参数
        api.addEventListener({
            name: 'selectCostEvt'
        }, function(ret, err) {
            $('#sel_cost').removeClass('aui-hide');
            $('#' + cost_id).find('.cost_name').text(ret.value.cost_name);
            $('#' + cost_id).find('.cost_name').attr('cost_id', ret.value.cost_id);
            var cost_ids = [];
            var cost_names = [];
            var new_cost_ids = [];
            var new_cost_names = [];
            $('.cost_name').each(function() {
                if ($(this).text() != '请选择成本中心') {
                    cost_ids.push($(this).attr('cost_id'));
                    cost_names.push($(this).text());
                }
            })
            new_cost_ids = $.unique(cost_ids);
            new_cost_names = $.unique(cost_names);
            var html = '';
            $('#select_cost').parent().removeClass('aui-hide');
            $('#select_cost').empty();
            for (var i in new_cost_ids) {
                html += '<div class="u_info">'
                html += '<div class="aui-list-item-inner last_cost" style="overflow: auto;text-align: center;border-bottom: 1px solid #E0E0E0">';
                html += '<div class="aui-list-item-label" style="width:20%;float: left;height: 2rem;line-height: 2rem;">';
                if (i == 0) {
                    html += '<input class="aui-radio" type="radio" name="cost_id" onchange="get_gpprove_info(this)" checked="checked" value="' + new_cost_ids[i] + '"></div>';
                    cost_center_id = new_cost_ids[i];
                } else {
                    html += '<input class="aui-radio" type="radio" name="cost_id" onchange="get_gpprove_info(this)"  value="' + new_cost_ids[i] + '"></div>';
                }
                html += '<div class="aui-list-item-input" style="width:80%;float: right;height: 2rem;line-height: 2rem;">';
                html += '<div style="float: left;">';
                html += '<span style="font-size: 0.8rem;font-weight: bold;" class="last_cost_name">' + new_cost_names[i] + '</span>';
                html += '</div></div>';
                html += '<div class="hint_msg" style="text-align: left;text-indent: 2em;color: #FF0000;font-size: 0.7rem;"></div>';
                html += '</div></div>';
            }
            $('#select_cost').append(html);
            $("input[name=cost_id]").eq(0).trigger('change', [this]);

        });

    }
    //获取证件信息
    function get_card_info() {
        //监听证件信息返回参数
        api.addEventListener({
            name: 'selectCard'
        }, function(ret, err) {
            console.log(user_id);
            $('#' + user_id).find('.card_type').text(ret.value.card_name);
            $('#' + user_id).find('.card_num').text(ret.value.card_number);
            $('#' + user_id).find('.card_type').attr('card_id', ret.value.card_id);
            $('#' + user_id).find('.card_type').attr('message_confirm', ret.value.issend);
            if (ret.value.issend == 1) {
                $('#' + user_id).find('.send_sms').text('发送短信');
            } else {
                $('#' + user_id).find('.send_sms').text('不发送短信');
            }
        });
    }
    //选择证件信息
    function select_card_info(obj) {
        user_id = $(obj).attr('id');
        var u_id = $(obj).parents('.user_list').find('.travel_user_id').text();
        var travels_id = $(obj).parents('.user_list').find('.travels_id').text();
        var u_index = $(obj).parents('.user_list').index();
        var u_type = 1;
        if (travels_id != 'undefined') {
            u_type = 0;
            u_id = travels_id;
        }
        api.openWin({
            name: 'update_passenger_frm',
            url: '../train/update_passenger_frm.html',
            pageParam: {
                u_type: u_type,
                u_id: u_id,
                u_index: u_index,
                user_name: $(obj).find('.user_name').text(),
                user_moble: $(obj).parents('.user_list').find('.mobile').text()
            }
        });

    }

    //获取当前成本中心的审核人信息
    function get_gpprove_info(obj) {
        $('.hint_msg').text('');
        var cost_id = $(obj).val();
        var param = {};
        param.url = Config.common.getApproveInfo;
        param.data = {
            cost_center_id: cost_id
        };
        ajax(param, function(data) {
            var approve_name = [];
            var approve_id = [];
            if (data.code == 1) {
                res = data.data;
                $.each(res, function(key, val) {
                    approve_name[key] = val.user_name;
                    approve_id[key] = val.user_id;
                })

                $(obj).attr('approve_name', approve_name.toString());
                $(obj).attr('approve_id', approve_id.toString());
                // is_violation = $api.getStorage('is_violation');
                if (is_violation == 'false') {
                    var msg = '不需要审批';
                } else {
                    var msg = '不需要审批';
                    if (approve_id.toString().indexOf(userId) == -1) {
                        var msg = '需要审批' + ',审批人为' + approve_name.toString();
                    }
                }

                //判断违规情况下一个人的审批情况
                if ($api.getStorage('trip_policy') === 0 || is_violation === 'true' && people_num == 1 && approve_type == '免审') {
                    var msg = '不需要审批';
                }
                $(obj).parents('.last_cost').find('.hint_msg').text(msg);
            }
        })

    }
</script>
